package cn.edu.xmu.experiment.PulseComms.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;

@Configuration
public class RabbitMQConfig {

    public static final String PRIVATE_EXCHANGE = "private.exchange";
    public static final String GROUP_EXCHANGE = "group.exchange";

    @Bean
    public DirectExchange privateExchange() {
        return new DirectExchange(PRIVATE_EXCHANGE);
    }

    @Bean
    public FanoutExchange groupExchange() {
        return new FanoutExchange(GROUP_EXCHANGE);
    }

    // 直接定义队列，而不是通过参数传入队列名称
    @Bean
    public Queue queueA() {
        return new Queue("queueA", true);
    }

    @Bean
    public Queue queueB() {
        return new Queue("queueB", true);
    }

    @Bean
    public Binding privateBindingA(Queue queueA, DirectExchange privateExchange) {
        return BindingBuilder.bind(queueA).to(privateExchange).with(queueA.getName());
    }

    @Bean
    public Binding privateBindingB(Queue queueB, DirectExchange privateExchange) {
        return BindingBuilder.bind(queueB).to(privateExchange).with(queueB.getName());
    }

    @Bean
    public Binding groupBindingA(Queue queueA, FanoutExchange groupExchange) {
        return BindingBuilder.bind(queueA).to(groupExchange);
    }

    @Bean
    public Binding groupBindingB(Queue queueB, FanoutExchange groupExchange) {
        return BindingBuilder.bind(queueB).to(groupExchange);
    }

    @Bean
    public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
        return new RabbitAdmin(connectionFactory);
    }


}
